Skip to content

[REFACTOR][RUNTIME] Phase out tvm::runtime::regex_match#19620

Merged
spectrometerHBH merged 2 commits into
apache:mainfrom
tqchen:tvm-phase-out-regex-match
May 27, 2026
Merged

[REFACTOR][RUNTIME] Phase out tvm::runtime::regex_match#19620
spectrometerHBH merged 2 commits into
apache:mainfrom
tqchen:tvm-phase-out-regex-match

Conversation

@tqchen
Copy link
Copy Markdown
Member

@tqchen tqchen commented May 27, 2026

Summary

tvm::runtime::regex_match was a thin C++ wrapper that bounced through a
global ffi::Function back into Python's re.match. It was introduced
solely to avoid pulling <regex> into TVM (libstdc++ dual-ABI conflict with
pre-cxx11 pytorch wheels). The only C++ caller is the DNNL JSON runtime, where
every pattern reduces to substring containment — re.match anchors at the
start only, so .*X.* is equivalent to s.find(X) != npos.

  • Remove src/runtime/regex.{h,cc} and the Python tvm.runtime.regex_match
    global registration.
  • Add file-local contains / contains_any helpers in dnnl_json_runtime.cc
    and inline std::string::find at the 15 call sites.
  • Drop the dead regex.h include from src/relax/transform/update_param_struct_info.cc.

No CMakeLists.txt change needed — src/runtime/*.cc is picked up by glob.

USE_DNNL is OFF in the ci_gpu container, so DNNL-specific runtime tests
are not exercised locally. The DNNL translation unit compiles cleanly with
the inlined helpers, and the full TVM build (636 targets) passes.

tvm::runtime::regex_match was a thin C++ wrapper that bounced through a
global ffi::Function back into Python's re.match — introduced solely to
avoid pulling <regex> into TVM (libstdc++ dual-ABI conflict with pre-cxx11
pytorch wheels). The only C++ caller is the DNNL JSON runtime, where
every pattern reduces to substring containment.

- Remove src/runtime/regex.{h,cc} and the python tvm.runtime.regex_match
  global registration.
- Inline std::string::find checks at the DNNL JSON runtime call sites.
- Drop the dead regex.h include from the relax update_param_struct_info
  pass.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the tvm.runtime.regex_match utility and its associated C++ and Python implementations, replacing regex-based operations in the DNNL JSON runtime with simpler, more efficient string matching helpers (contains and contains_any). The review feedback suggests improving the flexibility of the contains_any helper by implementing it as a C++17 variadic template with a fold expression, which would also allow simplifying the call sites in the subgraph engine construction.

Comment thread src/runtime/contrib/dnnl/dnnl_json_runtime.cc Outdated
Comment thread src/runtime/contrib/dnnl/dnnl_json_runtime.cc Outdated
Replace the fixed three-argument contains_any helper with a C++17
variadic template + fold expression. With the more general form, fold
the back-to-back deconv1d/2d/3d and conv*_transpose checks into a
single call (branch-order intact — the merged check still precedes
the plain conv check).
@spectrometerHBH spectrometerHBH merged commit f0ac8d6 into apache:main May 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants